import { defineStore } from 'pinia'
import { IFLoginResponse, IFMenus, IFuserInfo } from '@/api/types/common'
// useStore could be anything like useUser, useCart
// the first argument is a unique id of the store across your application
export const userStore = defineStore('user', {
  state: () => ({
    user: null as IFuserInfo | null,
    token: '',
    menus: [] as IFMenus[]
  }),
  actions: {
    setUser (userInfo: IFLoginResponse) {
      this.user = userInfo.user_info
      this.token = userInfo.token
      this.menus = userInfo.menus
    },
    resetUser () {
      this.user = null
      this.token = ''
      this.menus = []
    }
  },
  persist: {
    enabled: true
  }
})
